<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #ggk {
            width: 600px;
            height: 400px;
            font-size: 30px;
            text-align: center;
            line-height: 400px;
            overflow: hidden;
            position: absolute;
            left: 0;
            top: 0;
        }

        canvas {
            position: absolute;
            left: 0;
            top: 0;
            z-index: 2;
        }
    </style>
</head>

<body>
    <div id="ggk"></div>
    <canvas id="c1" width="600" height="400"></canvas>

    <script>
        /** @type {HTMLCanvasElement} */
        // 画布
        let c1 = document.getElementById("c1")
        // 画笔
        let ctx = c1.getContext("2d")
        let img = new Image()
        img.src = "./img/bg.png"
        img.onload = function () {
            ctx.drawImage(img, 0, 0, 600, 400)
            let random = Math.random()
            if (random < 0.1) {
                ggk.innerHTML = "抽中iphone14 Pro max"
            } else {
                ggk.innerHTML = "谢谢惠顾"
            }
        }
        let isDraw = false
        c1.onmousedown = function () {
            isDraw = true
        }
        c1.onmouseup = function () {
            isDraw = false
        }
        c1.onmousemove = function (e) {
            if (isDraw) {
                let x = e.pageX
                let y = e.pageY
                ctx.globalCompositeOperation = "destination-out"
                ctx.beginPath()
                ctx.arc(x, y, 20, 0, Math.PI * 2)
                ctx.fill()
            }
        }
    </script>
</body>

</html>